import { Component, Input, OnInit } from '@angular/core';
import { SFSchema } from '@delon/form';
import { ApiService } from '@core/services/api';
import { HttpClient } from '@angular/common/http';
import { NzMessageService, NzModalRef } from 'ng-zorro-antd';

@Component({
  selector: 'app-pwd-set',
  templateUrl: './pwd-set.component.html',
  styles: ['>>>.ant-input-number{width:100% !important;}']
})
export class PwdSetComponent implements OnInit {
  @Input()
  set _record(value){
    console.log(value)
        if(!value) return
        this.param = value
  }
  param:any
  schema: SFSchema = {
    properties: {
      devicePassword: {
        type: 'number',
        title: '密码',
        maxLength:6
      },
    },
    required: ['devicePassword']
  }
  constructor(
    private api: ApiService,
    private http: HttpClient,
    private msg: NzMessageService,
    private modalRef: NzModalRef
  ) { }
  formSubmit(data) {
    const pwd = data.devicePassword + ""
    if(pwd.length>6){
      this.msg.error("只能输入6位数字")
      return
    }
    this.http.post("/core/host/rke/updateOpenPassword",{deviceId:this.param.id,devicePassword:data.devicePassword}).subscribe((res:any) => {
      if (res.status === '200' || res.status === '201') {
        this.msg.success('操作成功');
        this.modalRef.triggerOk();
      } else {
        this.msg.error(res.message)
      }
    })
  }
  ngOnInit() {
  }

}
